import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;


//生产者消费模型
public class Demo1 {
    public static void main(String[] args) {
        BlockingQueue<Integer> que = new LinkedBlockingQueue<>();

        Thread t  = new Thread(() -> {
            while(true) {
                try {
                    int value = que.take();
                    System.out.println("消费元素:" + value);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        t.start();


        Thread t1 = new Thread(()-> {
            int n = 0;
            while(true) {

                try {
                    que.put(n);
                    System.out.println("生产元素:"+ n);
                    n++;
                    Thread.sleep(500);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t1.start();
    }
}
